﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;

namespace AcademicPlanner.Framework.Libraries.Mvc
{
	[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
	public sealed class AjaxOnlyAttribute : FilterAttribute, IActionFilter
	{

		public void OnActionExecuted(ActionExecutedContext filterContext)
		{
			
		}

		public void OnActionExecuting(ActionExecutingContext filterContext)
		{
			if (!filterContext.HttpContext.Request.IsAjaxRequest())
			{
				throw new HttpException(404, "The action requested is available through ajax only!");
			}
		}

	}
}
